﻿<?php
	include '../inc/conn.php';

	session_start();
	extract($_POST);
	extract($_GET);
	$pagestr = end(explode("/",$_SERVER['PHP_SELF']));
	unset($_POST,$_GET);
	
	if (isset($act))
	{
		if ($act == 'add' && isset($_SESSION['logname']))
		{
			if(empty($vRemark))
				$vRemark='N/A';
			
			$db = new mysql();
			$sql="INSERT INTO `weekly_report` (`DEPT`, `Issues`, `Risks`, `WeDid`, `WillDo`, `Project`, `Trigger date`, `Issue date`, `Owner`, `Status`, `Remark`) values 
				('${_SESSION['dept']}', '".htmlspecialchars(${vIssues}, ENT_QUOTES)."', '".htmlspecialchars(${vRisks}, ENT_QUOTES)."', '".htmlspecialchars(${vWeDid}, ENT_QUOTES)."', '"
				.htmlspecialchars(${vWilldo}, ENT_QUOTES)."', '".htmlspecialchars(${vProject}, ENT_QUOTES)."', '${vTriggerdate}', '${vIssuedate}', '${vOwner}', '${vStatus}', '".htmlspecialchars(${vRemark}, ENT_QUOTES)."')";
			$db->query($sql);
			$db->close();
			echo "<script>alert('数据添加成功!');window.opener.location.reload();window.close();</script>";
		}

		if ($act == 'change' && isset($_SESSION['logname']))
		{
			if(empty($vRemark))
				$vRemark='N/A';

			$db = new mysql();
			$table = "weekly_report";
			$condition = "ID=${id}";
			$mod_content="`Issues`='".htmlspecialchars(${vIssues}, ENT_QUOTES)."', `Risks`='".htmlspecialchars(${vRisks}, ENT_QUOTES)."', `WeDid`='".htmlspecialchars(${vWeDid}, ENT_QUOTES)."',
				`WillDo`='".htmlspecialchars(${vWilldo}, ENT_QUOTES)."', `Project`='".htmlspecialchars(${vProject}, ENT_QUOTES)."', `Trigger date`='${vTriggerdate}', `Issue date`='${vIssuedate}', `Owner`='${vOwner}', `Status`='${vStatus}', `Remark`='".htmlspecialchars(${vRemark}, ENT_QUOTES)."'";
			$db->update($table, $mod_content, $condition);
			$db->close();
			echo "<script>alert('内容修改完成!');window.opener.location.reload();window.close();</script>";
		}
	}
?>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="content-type" content="text/html;charset=utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<!-- <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">-->
	<link rel="stylesheet" href="/css/bootstrap.min.css">
	<link rel="stylesheet" href="/css/bootstrap-datetimepicker.min.css">	
	<script type="text/javascript" src="/js/jquery.min.js"></script>
	<script type="text/javascript" src="/js/jquery-migrate.min.js"></script>
	<script type="text/javascript" src="/xhEditor/xheditor.min.js"></script>
	<script type="text/javascript" src="/xhEditor/xheditor_lang/zh-cn.js"></script>
	<script type="text/javascript" src="/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="/js/bootstrap-datetimepicker.min.js"></script>
	<script>
		$(function(){
			$("#addbtn").click(function(){
				if ($("#vIssues").val() == ""){
					alert("Problem summary没有填写！");
					return false;
				}
	
				if ($("#vRisks").val() == ""){
					alert("What Risk will没有填写！");
					return false;
				}
				
				if ($("#vWeDid").val() == ""){
					alert("What we did没有填写！");
					return false;
				}
	
				if ($("#vWilldo").val() == ""){
					alert("What we can do没有填写！");
					return false;
				}
	
				if ($("#vProject").val() == ""){
					alert("Project没有填写！");
					return false;
				}
				
				if ($("#vTriggerdate").val() == ""){
					alert("Trigger date没有填写！");
					return false;
				}
				
				if ($("#vOwner").val() == ""){
					alert("Owner没有填写！");
					return false;
				}
				
				if ($("#vIssuedate").val() == ""){
					alert("Issue date没有填写！");
					return false;
				}
			});
			$('#vTriggerdate').datetimepicker({
				format: 'yyyy-mm-dd',
				weekStart: 1,
				autoclose: true,
				startView: 2,
				minView: 2,
				pickerPosition: 'top-right'
			});

			$('#vIssuedate').datetimepicker({
				format: 'yyyy-mm-dd',
				weekStart: 1,
				autoclose: true,
				startView: 2,
				minView: 2,
				pickerPosition: 'top-right'
			});	
		});
	</script>
<?
	if ($pagename=="additem")		echo "<title>增加周报内容</title>\n";
	if ($pagename=="changeitem")	echo "<title>修改周报内容</title>\n";
	if ($pagename=="reviewitem")	echo "<title>查看周报内容</title>\n";
	if ($pagename=="report")		echo "<title>周报报告</title>\n";

	echo "</head>\n";
	echo "<body class='background'>\n";
		if($pagename=="report"){
			// generate weekly_report for meeting
			$sStatus="'NOP'";
			if(isset($isCrisis))	$sStatus.=",'Crisis'";
			if(isset($isCritical))	$sStatus.=",'Critical'";
			if(isset($isMinor))		$sStatus.=",'Minor'";
			if(isset($isTracking))	$sStatus.=",'Tracking'";
			if(isset($isClosed))	$sStatus.=",'Closed'";

			if(isset($isDept) || isset($isTracking) || isset($isMinor) || isset($isCritical) || isset($isCrisis) || isset($isClosed))
			{
				$sStatus= "where DEPT='$isDept' and (Status in ($sStatus) )";
			}else
				$sStatus=" ";
?>
			<table class='table table-hover table-bordered'>
				<caption>
					<form action='weekly_report.php=?pagename=report' method='post'>
						状态【&nbsp;		Crisis: <input type='checkbox' name='isCrisis' value='1' 		<? if(isset($isCrisis)) echo "checked='checked'"; ?> />
								&nbsp;&nbsp;Critical: <input type='checkbox' name='isCritical' value='1' 	<? if(isset($isCritical)) echo "checked='checked'"; ?> />
								&nbsp;&nbsp;Minor: <input type='checkbox' name='isMinor' value='1' 			<? if(isset($isMinor)) echo "checked='checked'"; ?> />
								&nbsp;&nbsp;Tracking: <input type='checkbox' name='isTracking' value='1' 	<? if(isset($isTracking)) echo "checked='checked'"; ?> />
								&nbsp;&nbsp;Closed: <input type='checkbox' name='isClosed' value='1' 		<? if(isset($isClosed)) echo "checked='checked'"; ?> />
						&nbsp;】			
						&nbsp;&nbsp;<strong>部门: </strong>
						<select name='isDept' id='isDept'>
							<option value="EE" <? if($isDept=="EE") echo 'selected="selected"'; ?> >EE</option>
							<option value="TE" <? if($isDept=="TE") echo 'selected="selected"'; ?> >TE</option>
							<option value="PE" <? if($isDept=="PE") echo 'selected="selected"'; ?> >PE</option>
							<option value="RT" <? if($isDept=="RT") echo 'selected="selected"'; ?> >RT</option>
						</select>&nbsp;&nbsp;<button type='submit' class='btn btn-info'>筛选</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://10.100.160.166/export-wk.php'><b><span class="glyphicon glyphicon-cloud-download"></span> 导出报告</b></a>
					</form>
				</caption>
				<thead>
					<tr class='success'>
						<th style='width: 1%'>Item</th><th style='width: 1%'>Dept.</th>
						<th style='width: 8%'>Problem summary</th><th style='width: 8%'>What Risk will...? </th>
						<th style='width: 20%'>What we did</th><th style='width: 20%'>What we can do ?</th>
						<th style='width: 4%'>Project</th><th style='width: 6%'>Trigger date</th>
						<th style='width: 4%'>Issue date</th><th style='width: 3%'>Owner</th>
						<th style='width: 3%'>Status</th><th style='width: 4%'>Remark</th>		
					</tr>
				</thead>
				<tbody>
<?			
			$db = new mysql();
			$db->query("select * from weekly_report $sStatus");
			$num = $db->db_num_rows();
			for($i=0; $i<$num; $i++){
				$row = $db->fetch_assoc();
				$item = $i + 1;
				echo "			<tr>";
				echo "				<td style='vertical-align: middle;text-align: center;'>$item</td>";
				echo "				<td style='vertical-align: middle;text-align: center;'>${row['DEPT']}</td>";
				echo "				<td style='vertical-align: middle;text-align: left;'><a href='#' rel='tooltip' title='查看详细' onclick=\"javascript:window.open('weekly_report.php?pagename=reviewitem&id=${row['ID']}', '查看', 'height=860, width=1000, toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=no');\">".htmlspecialchars_decode($row['Issues'])."</a></td>";
				echo "				<td style='vertical-align: middle;text-align: left;'>".htmlspecialchars_decode($row['Risks'])."</td>";
				echo "				<td>".htmlspecialchars_decode($row['WeDid'])."</td>";
				echo "				<td>".htmlspecialchars_decode($row['WillDo'])."</td>";
				echo "				<td style='vertical-align: middle;text-align: left;'>".htmlspecialchars_decode($row['Project'])."</td>";
				echo "				<td style='vertical-align: middle;text-align: left;'>".htmlspecialchars_decode($row['Trigger date'])."</td>";
				echo "				<td style='vertical-align: middle;text-align: left;'>".htmlspecialchars_decode($row['Issue date'])."</td>";
				echo "				<td style='vertical-align: middle;text-align: left;'>".htmlspecialchars_decode($row['Owner'])."</td>";
				if($row['Status']=='Crisis')	echo "<td style='vertical-align: middle;text-align: center;background:#c00000'>C</td>";
				if($row['Status']=='Critical')	echo "<td style='vertical-align: middle;text-align: center;background:#ff0000'>R</td>";
				if($row['Status']=='Minor')		echo "<td style='vertical-align: middle;text-align: center;background:#ffff00'>Y</td>";
				if($row['Status']=='Tracking')	echo "<td style='vertical-align: middle;text-align: center;background:#e6b8b7'>T</td>";
				if($row['Status']=='Closed')	echo "<td style='vertical-align: middle;text-align: center;background:#bbbbbb'>Closed</td>";
				echo "				<td>".htmlspecialchars_decode($row['Remark'])."</td>";			
				echo "			</tr>\n";
			}
			echo "		</tbody>";
			echo "	</table>";
			$db->close();
		}

	if(isset($_SESSION['logname'])){
		echo "<div class='container-fluid white-background pagecontent'>";
		if ($pagename=="reviewitem"){
			$db = new mysql();
			$sql="select * from weekly_report where ID=$id";
			$db->query($sql);
			$num = $db->db_num_rows();
			$row = $db->fetch_assoc();
			
			echo "<div class='panel panel-info'>";
			echo "	<div class='panel-heading'>";
			echo "		<h3 class='panel-title'>问题描述</h3>";
			echo "	</div>";
			echo "	<div class='panel-body'>";
				echo "<div>".htmlspecialchars_decode($row['Issues'])."</div>";
			echo "	</div>";
			echo "</div>";
			
			echo "<div class='panel panel-info'>";
			echo "	<div class='panel-heading'>";
			echo "		<h3 class='panel-title'>影响与潜在风险</h3>";
			echo "	</div>";
			echo "	<div class='panel-body'>";
				echo "<div>".htmlspecialchars_decode($row['Risks'])."</div>";
			echo "	</div>";
			echo "</div>";
			echo "<div class='panel panel-success'>";
			echo "	<div class='panel-heading'>";
			echo "		<h3 class='panel-title'>我们已做的</h3>";
			echo "	</div>";
			echo "	<div class='panel-body'>";
				echo "<div>".htmlspecialchars_decode($row['WeDid'])."</div>";
			echo "	</div>";
			echo "</div>";
			echo "<div class='panel panel-danger'>";
			echo "	<div class='panel-heading'>";
			echo "		<h3 class='panel-title'>我们能做的</h3>";
			echo "	</div>";
			echo "	<div class='panel-body'>";
				echo "<div>".htmlspecialchars_decode($row['WillDo'])."</div>";
			echo "	</div>";
			echo "</div>";
			echo "<div class='panel panel-info'>";
			echo "	<div class='panel-heading'>";
			echo "		<h3 class='panel-title'>项目专案</h3>";
			echo "	</div>";
			echo "	<div class='panel-body'>";
				echo "<div>".htmlspecialchars_decode($row['Project'])."</div>";
			echo "	</div>";
			echo "</div>";	
			echo "<div class='panel panel-warning'>";
			echo "	<div class='panel-heading'>";			
			echo "		<h3 class='panel-title'>状态日期</h3>";
			echo "	</div>";
			echo "	<div class='panel-body'>";
				echo "<strong class='text-danger'>触发日期：</strong>".htmlspecialchars_decode($row['Trigger date'])."&nbsp;&nbsp;&nbsp;&nbsp;<strong  class='text-warning'>发生日期：</strong>".htmlspecialchars_decode($row['Issue date']);
				echo "&nbsp;&nbsp;&nbsp;&nbsp;<strong class='text-primary'>所有者：</strong>".htmlspecialchars_decode($row['Owner'])."&nbsp;&nbsp;&nbsp;&nbsp;<strong class='text-primary'>问题状态：</strong>";
				if ($row['Status']=="Crisis")	echo "<font color=\"darkred\">";
				if ($row['Status']=="Critical")	echo "<font color=\"red\">";
				if ($row['Status']=="Minor")	echo "<font color=\"Yellow\">";
				if ($row['Status']=="Tracking")	echo "<font color=\"BLUE\">";
				echo $row['Status']."</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;操作：<a href='weekly_report.php?pagename=changeitem&id=${row['ID']}'><span class=\"glyphicon glyphicon-edit\"></span>修改？</a>";
			echo "</div>";
			$db->close();
		}
		// Add new item page
		if ($pagename=="additem"){

		echo "<div id='ADDDIV'>\n";
		echo "	<form action='$pagestr?act=add' method='post'>\n";
?>
		<div class='row'>
			<div class='col-md-6 col-lg-4'><strong>Problem summary:</strong><br />
			<textarea name='vIssues' id='vIssues' rows='4' cols='40' class="xheditor {tools:'Fullscreen',skin:'default', upImgUrl:'upload.php?immediate=1'}" style="width:100%;height:100px;"></textarea>
			</div>
			<div class='col-md-6 col-lg-4'><strong>What Risk will...?:</strong><br />
			<textarea name='vRisks' id='vRisks' rows='4' cols='40' class="xheditor {tools:'Fullscreen',skin:'default', upImgUrl:'upload.php?immediate=1'}" style="width:100%;height:100px;"></textarea>
			</div>
		</div><br />
		<div class='row'>
			<div class='col-md-6 col-lg-4'><strong>What we did:</strong><br />
			<textarea name='vWeDid' id='vWeDid' rows='12' cols='80' class="xheditor {tools:'full',skin:'default', upImgUrl:'upload.php?immediate=1'}" style="width:100%;height:120px;"></textarea>
			</div>
			<div class='col-md-6 col-lg-4'><strong>What we can do?:</strong><br />
			<textarea name='vWilldo' id='vWilldo' rows='12' cols='80' class="xheditor {tools:'full',skin:'default', upImgUrl:'upload.php?immediate=1'}" style="width:100%;height:120px;"></textarea>
			</div>
		</div><br />
		<div class='row'>
			<div class='col-md-6 col-lg-4'><strong>Project:</strong><br />
			<textarea name='vProject' id='vProject' rows='12' cols='80' class="xheditor {tools:'full',skin:'default'}" style="width:100%;height:100px;"></textarea>
			</div>
			<div class='col-md-6 col-lg-4'><strong>Remark:</strong><br />
			<textarea name='vRemark' id='vRemark' rows='12' cols='80' class="xheditor {tools:'full',skin:'default', upImgUrl:'upload.php?immediate=1'}" style="width:100%;height:100px;"></textarea>
			</div>
		</div><br />
		<div class='row'>
		<div class='col-md-6 col-lg-4'><strong>Trigger date:</strong><input type='input' name='vTriggerdate' id='vTriggerdate' placeholder='2019-10-30'/></div>
		<!--   Here is the code for login user  -->
		<div class='col-md-6 col-lg-4'><strong>Owner:</strong><input type='input' name='vOwner' id='vOwner' value='<? echo $_SESSION['logchnname']; ?>'/></div>
		<div class='col-md-6 col-lg-4'><strong>Issue&nbsp;&nbsp;&nbsp; date:</strong><input type='input' name='vIssuedate' id='vIssuedate' placeholder='2019-11-21' /></div>
			<div class='col-md-6 col-lg-4'><strong>Status: </strong><select name='vStatus' id='vStatus'>
			<option value="Crisis">Crisis and high risk</option>';
			<option value="Critical">Critical item and Risk</option>';
			<option value="Minor">Minor item and Yellow</option>';
			<option value="Tracking">Tracking</option>';
		</select></div>
		</div>
			<div><br /><input class='btn btn-success btn-primary' name='submit' value='提交' type='submit' id='addbtn'>
		<input class='btn btn-danger' name='reset' value='重写' type='reset'></div>
<?
			echo "	</form>\n";
			echo "</div>\n";
		}
		// change item page
		if ($pagename=="changeitem"){
			$db = new mysql();
			$sql="select * from weekly_report where ID=$id";
			$db->query($sql);
			$num = $db->db_num_rows();
			$row = $db->fetch_assoc();
			echo "\n<form action='$pagestr?act=change&id=${row['ID']}' method='post'>\n";
			echo "<div class='row'>";
			echo "	<div class='col-md-6 col-lg-4'><strong>Problem summary:</strong><br />";
			echo "		<textarea name='vIssues' rows='12' cols='80' class=\"xheditor {tools:'Fullscreen',skin:'default', upImgUrl:'upload.php?immediate=1'}\" style=\"width:100%;height:100px;\">"
							.htmlspecialchars_decode($row['Issues'])."</textarea>";
			echo "		</div>\n";
			echo "		<div class='col-md-6 col-lg-4'><strong>What Risk will...?:</strong><br />";
			echo "		<textarea name='vRisks' rows='12' cols='80' class=\"xheditor {tools:'Fullscreen',skin:'default', upImgUrl:'upload.php?immediate=1'}\" style=\"width:100%;height:100px;\">"
							.htmlspecialchars_decode($row['Risks'])."</textarea>";
			echo "		</div>\n";
			echo "</div><br />\n";
			echo "<div class='row'>";
			echo "	<div class='col-md-6 col-lg-4'><strong>What we did:</strong><br />";
			echo "		<textarea name='vWeDid' rows='12' cols='80' class=\"xheditor {tools:'full',skin:'default', upImgUrl:'upload.php?immediate=1'}\" style=\"width:100%;height:180px;\">"
							.htmlspecialchars_decode($row['WeDid'])."</textarea>";
			echo "		</div>\n";
			echo "		<div class='col-md-6 col-lg-4'><strong>What we can do?:</strong><br />";
			echo "		<textarea name='vWilldo' rows='12' cols='80' class=\"xheditor {tools:'full',skin:'default', upImgUrl:'upload.php?immediate=1'}\" style=\"width:100%;height:180px;\">"
							.htmlspecialchars_decode($row['WillDo'])."</textarea>";
			echo "		</div>\n";
			echo "</div><br />\n";
			echo "<div class='row'>";
			echo "	<div class='col-md-6 col-lg-4'><strong>Project:</strong><br />";
			echo "		<textarea name='vProject' rows='12' cols='80' class=\"xheditor {tools:'Fullscreen',skin:'default', upImgUrl:'upload.php?immediate=1'}\" style=\"width:100%;height:100px;\">"
							.htmlspecialchars_decode($row['Project'])."</textarea>";
			echo "		</div>\n";			
			echo "		<div class='col-md-6 col-lg-4'><strong>Remark:</strong><br />";
			echo "		<textarea name='vRemark' rows='12' cols='80' class=\"xheditor {tools:'Fullscreen',skin:'default', upImgUrl:'upload.php?immediate=1'}\" style=\"width:100%;height:100px;\">"
							.htmlspecialchars_decode($row['Remark'])."</textarea>";
			echo "		</div>\n";
			echo "</div>\n<br />";
			echo "<div class='row'>";
			echo "	<div class='col-md-6 col-lg-4'><strong>Trigger date:</strong><input type='input' name='vTriggerdate' id='vTriggerdate' value='${row['Trigger date']}'/></div>\n";
			echo "	<div class='col-md-6 col-lg-4'><strong>Owner:</strong><input type='input' name='vOwner' id='vOwner' value='${row['Owner']}'/></div>\n";
			echo "	<div class='col-md-6 col-lg-4'><strong>Issue&nbsp;&nbsp;&nbsp; date:</strong><input type='input' name='vIssuedate' id='vIssuedate' value='${row['Issue date']}'/></div>\n";	
			echo "	<div class='col-md-6 col-lg-4'><strong>Status: </strong><select name='vStatus' id='vStatus'>";
			if ($row['Status'] == "Crisis")
				echo '<option value="Crisis" selected="selected">Crisis and high risk</option>';
			else
				echo '<option value="Crisis">Crisis and high risk</option>';
				
			if ($row['Status'] == "Critical") 
				echo '<option value="Critical" selected="selected">Critical item and Risk</option>';
			else
				echo '<option value="Critical">Critical item and Risk</option>';
			
			if ($row['Status'] == "Minor") 
				echo '<option value="Minor" selected="selected">Minor item and Yellow</option>';
			else
				echo '<option value="Minor">Minor item and Yellow</option>';
			
			if ($row['Status'] == "Tracking") 
				echo '<option value="Tracking" selected="selected">Tracking</option>';
			else
				echo '<option value="Tracking">Tracking</option>';

			if ($row['Status'] == "Closed") 
				echo '<option value="Closed" selected="selected">Closed</option>';
			else
				echo '<option value="Closed">Closed</option>';
			echo "	</select></div>\n";
			echo "</div>\n";
			echo "	<br /><div>\n<input class='btn btn-success btn-primary' name='submit' value='提交' type='submit'  id='addbtn'>\n";
			echo "  <input class='btn btn-danger' name='reset' value='重写' type='reset'>\n</div>\n";
			echo "</form>\n";
			$db->close();
		}
	}
?>
		</div>
	</body>
</html>

